<?php 
require_once('Zend/Mail.php');
require_once('Zend/Registry.php');
require_once('Zend/View.php');

class Core_Email
	extends Zend_Mail
{
	
    /**
     * Sets the subject of the message. Autotranslates
     *
     * @param   string    $subject
     * @return  Zend_Mail Provides fluent interface
     * @throws  Zend_Mail_Exception
     */
    public function setSubject($subject)
    {
		$translator = Zend_Registry::get('Zend_Translate');
		return parent::setSubject($translator->translate($subject));
    }
	
	/**
	 * This method creates a new email object whose content is sent through
	 * the template parser.
	 * 
	 * @param $textTemplatePath Path to the text template to render.
	 * @param $htmlTemplatePath Path to the html template to render.
	 * @param $data Associative array of data to pass to the view parser.
	 * @return Core_Email
	 */
	public static function createEmailFromTemplate( $textTemplatePath, $htmlTemplatePath, $data = array() )
	{
		// Create our email
		$email = new Core_Email();
		
		// Render our emails.
		$view = new Zend_View(array('encoding' => 'UTF-8')); 
		$view->addScriptPath( APPLICATION_PATH . '/views/scripts/email');
		$view->assign($data);
		
		$email->setBodyText ( $view->render( $textTemplatePath ) );
		$email->setBodyHtml ( $view->render( $htmlTemplatePath ) );
		
		return $email;
	}
	
}